﻿using System;
using System.Collections.Generic;

namespace DesignModeConsole.SolidPrinciple.single_responsibility_principle
{
    /// <summary>
    /// 单一责任原则
    /// </summary>
    public class Service
    {
        public void Test()
        {
            {
                //错误设计
                var shapes = new List<object> {
                        new Circle(2),
                        new Square(5),
                        new Square(6)
                };

                var areas = new AreaCalculator(shapes);
                Console.WriteLine(areas.Output());
            }

            {
                //符合单一职责的设计
                var shapes = new List<object> {
                        new Circle(2),
                        new Square(5),
                        new Square(6)
                };

                var areaCalculator = new AreaCalculator(shapes);
                var outputer = new SumCalculatorOutputter(areaCalculator);
                Console.WriteLine(outputer.JSON());
                Console.WriteLine(outputer.String());
            }
        }
    }
}